import { EnterpriseApi } from '@/api';

export default {
  name: 'ACompanySelector',
  props: {
    label: {
      type: String,
      default: '',
    },
  },
  data() {
    return {
      state: this.label,
    };
  },
  watch: {
    label: function () {
      this.state = this.label;
    },
  },
  methods: {
    async querySearchAsync(queryString, cb) {
      try {
        const response = await EnterpriseApi.page({
          page: 1,
          pageSize: 50,
          company_name: queryString,
        });
        cb(response.result.list);
      } catch (e) {}
    },
    handleSelect(value) {
      this.$emit('select', {
        company_id: value.company_id,
        company_name: value.company_name,
      });
    },
    handleChange(value) {
      console.log('on company selector changed: ', value);
      this.$emit('input', value);
    },
  },
};
